document.write("<script type=\"text/javascript\" src=\"../js/checkbox.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"../../seam/resources/lseam.js\"></script>");
document.write("<script type=\"text/javascript\" src=\"../../seam/resources/moduleRemote\"></script>");

// 验证模块表单
function checkModuleForm() {
	var moduleForm = document.forms[0];
	if(moduleForm.moduleName.value == "") {
		alert("请输入模块名称！");
		moduleForm.moduleName.focus();
		return false;
	}
	if(moduleForm.moduleType.value == "0") {
		moduleForm.moduleUrl.value = "";
		moduleForm.moduleUrl.disabled = true;
	}else if(moduleForm.moduleType.value == "1" && moduleForm.moduleUrl.value == ""){
		alert("请输入模块引导页地址！");
		moduleForm.moduleUrl.focus();
		return false;
	}
	return true;
}

// 添加模块
function addModule() {
	if(checkModuleForm()) {
		var moduleForm = document.forms[0];
		var vo = Lseam.getType("cn.line5.module.ModuleVo");
		vo.setParentId(moduleForm.parentId.value);
		vo.setModuleName(moduleForm.moduleName.value);
		vo.setModuleType(moduleForm.moduleType.value);
		vo.setModuleUrl(moduleForm.moduleUrl.value);
		vo.setModuleDesc(moduleForm.moduleDesc.value);
		Lseam.getComponent("moduleRemote").addModule(vo, function(result) {
    		if(result){
    			alert("添加成功！");
    			window.location.href = "moduleList.seam?moduleId=" + moduleForm.parentId.value;
    		}else{
    			alert("添加失败，请稍候重试！");
    		}
    	});
	}
}

// 编辑模块
function editModule() {
	if(getCheckedNum("moduleIds") != 1) {
		alert("必须且只能选择一条编辑的模块！");
		return;
	}
	window.location.href = "moduleEdit.seam?moduleId=" + getCheckboxValue("moduleIds");
}

// 修改模块
function modifyModule(tag) {
	if(checkModuleForm()) {
		var moduleForm = document.forms[0];
		var vo = Lseam.getType("cn.line5.module.ModuleVo");
		vo.setModuleId(moduleForm.moduleId.value);
		vo.setModuleName(moduleForm.moduleName.value);
		vo.setModuleUrl(moduleForm.moduleUrl.value);
		vo.setModuleDesc(moduleForm.moduleDesc.value);
		Lseam.getComponent("moduleRemote").modifyModule(vo, function(result) {
    		if(result) {
    			alert("修改成功！");
    			if(tag == "main")
    				window.location.href = "moduleInfo.seam?moduleId=" + moduleForm.moduleId.value;
    			else
    				window.location.href = "moduleList.seam?moduleId=" + moduleForm.moduleId.value.substring(0, moduleForm.moduleId.value.length - 3);
    		} else
    			alert("修改失败，请稍候重试！");
    	});
	}
}

// 删除模块
function deleteModule() {
	if(getCheckedNum("moduleIds") <= 0){
		alert("请选择要删除的模块！");
		return;
	}
	if(confirm("该操作将删除选择的模块及所属子模块和功能，确定继续吗？")) {
		var moduleForm = document.forms[0];
		moduleForm.method = "post";
		moduleForm.action = "moduleDelete.seam";
		moduleForm.submit();
	}
}

// 模块向上排序
function upModule(moduleId) {
	Lseam.getComponent("moduleRemote").upModule(moduleId, function(result) {
		if(result)
			window.location.reload();
		else
			alert("排序操作失败，请稍候重试！");
	});
}

// 模块向下排序
function downModule(moduleId) {
	Lseam.getComponent("moduleRemote").downModule(moduleId, function(result) {
		if(result)
			window.location.reload();
		else
			alert("排序操作失败，请稍候重试！");
	});
}

// 设置模块引导页是否可写
function setModuleUrl() {
	var moduleForm = document.forms[0];
	if(moduleForm.moduleType.value == "0") {
		moduleForm.moduleUrl.value = "";
		moduleForm.moduleUrl.disabled = true;
	} else
		moduleForm.moduleUrl.disabled = false;
}

// 控制textarea长度
function limitLong(obj, length) {
	return obj.value.length < length || event.keyCode == 8;
}

// 验证功能表单
function checkFunctionForm() {
	var functionForm = document.forms[0];
	if(functionForm.functionName.value == "") {
		alert("请输入功能名称！");
		functionForm.functionName.focus();
		return false;
	}
	return true;
}

// 添加功能
function addFunction() {
	if(checkFunctionForm()) {
		var functionForm = document.forms[0];
		var vo = Lseam.getType("cn.line5.module.ModuleFunctionVo");
		vo.setFunctionId(functionForm.functionId.value);
		vo.setFunctionName(functionForm.functionName.value);
		vo.setFunctionDesc(functionForm.functionDesc.value);
		Lseam.getComponent("moduleRemote").addFunction(vo, function(result) {
    		if(result != null){
    			alert("添加成功！");
    			window.location.href = "functionList.seam?moduleId=" + functionForm.functionId.value;
    		}else{
    			alert("添加失败，请稍候重试！");
    		}
    	});
	}
}

// 添加并继续添加功能点功能
function addFunctionAndAddPoint() {
	if(checkFunctionForm()) {
		var functionForm = document.forms[0];
		var vo = Lseam.getType("cn.line5.module.ModuleFunctionVo");
		vo.setFunctionId(functionForm.functionId.value);
		vo.setFunctionName(functionForm.functionName.value);
		vo.setFunctionDesc(functionForm.functionDesc.value);
		Lseam.getComponent("moduleRemote").addFunction(vo, function(result) {
    		if(result != null){
    			alert("添加成功！");
    			window.location.href = "functionEdit.seam?functionId=" + result.functionId;
    		}else{
    			alert("添加失败，请稍候重试！");
    		}
    	});
	}
}

// 编辑功能
function editFunction() {
	if(getCheckedNum("functionIds") != 1) {
		alert("必须且只能选择一条编辑的功能！");
		return;
	}
	window.location.href = "functionEdit.seam?functionId=" + getCheckboxValue("functionIds");
}

// 修改功能
function modifyFunction() {
	if(checkFunctionForm()) {
		var functionForm = document.forms[0];
		var vo = Lseam.getType("cn.line5.module.ModuleFunctionVo");
		vo.setFunctionId(functionForm.functionId.value);
		vo.setFunctionName(functionForm.functionName.value);
		vo.setFunctionDesc(functionForm.functionDesc.value);
		Lseam.getComponent("moduleRemote").modifyFunction(vo, function(result) {
    		if(result) {
    			alert("修改成功！");
   				window.location.href = "functionList.seam?moduleId=" + functionForm.functionId.value.substring(0, functionForm.functionId.value.length - 3);
    		} else
    			alert("修改失败，请稍候重试！");
    	});
	}
}

// 修改并继续维护功能点功能
function modifyFunctionAndAddPoint() {
	if(checkFunctionForm()) {
		var functionForm = document.forms[0];
		var vo = Lseam.getType("cn.line5.module.ModuleFunctionVo");
		vo.setFunctionId(functionForm.functionId.value);
		vo.setFunctionName(functionForm.functionName.value);
		vo.setFunctionDesc(functionForm.functionDesc.value);
		Lseam.getComponent("moduleRemote").modifyFunction(vo, function(result) {
    		if(result) {
    			alert("修改成功！");
   				window.location.href = "functionEdit.seam?functionId=" + functionForm.functionId.value;
    		} else
    			alert("修改失败，请稍候重试！");
    	});
	}
}

// 删除功能
function deleteFunction() {
	if(getCheckedNum("functionIds") <= 0){
		alert("请选择要删除的功能！");
		return;
	}
	if(confirm("该操作将删除选择的功能以及所属功能点，确定继续吗？")) {
		var functionForm = document.forms[0];
		functionForm.method = "post";
		functionForm.action = "functionDelete.seam";
		functionForm.submit();
	}
}

// 功能向上排序
function upFunction(functionId) {
	Lseam.getComponent("moduleRemote").upFunction(functionId, function(result) {
		if(result)
			window.location.reload();
		else
			alert("排序操作失败，请稍候重试！");
	});
}

// 功能向下排序
function downFunction(functionId) {
	Lseam.getComponent("moduleRemote").downFunction(functionId, function(result) {
		if(result)
			window.location.reload();
		else
			alert("排序操作失败，请稍候重试！");
	});
}





// 验证功能点表单
function checkPointForm() {
	var pointForm = document.forms[0];
	if(pointForm.pointName.value == "") {
		alert("请输入功能点名称！");
		pointForm.pointName.focus();
		return false;
	}
	if(pointForm.componentName.value == "") {
		alert("请输入组件名！");
		pointForm.componentName.focus();
		return false;
	}
	if(pointForm.methodName.value == "") {
		alert("请输入方法名！");
		pointForm.methodName.focus();
		return false;
	}
	return true;
}

// 添加功能点
function addPoint() {
	if(checkPointForm()) {
		var pointForm = document.forms[0];
		var vo = Lseam.getType("cn.line5.module.ModuleFunctionPointVo");
		vo.setFunctionId(pointForm.functionId.value);
		vo.setPointName(pointForm.pointName.value);
		vo.setComponentName(pointForm.componentName.value);
		vo.setMethodName(pointForm.methodName.value);
		Lseam.getComponent("moduleRemote").addPoint(vo, function(result) {
    		if(result != null){
    			alert("添加成功！");
    			window.location.href = "pointList.seam?functionId=" + pointForm.functionId.value;
    		}else{
    			alert("添加失败，请稍候重试！");
    		}
    	});
	}
}

// 编辑功能点
function editPoint() {
	if(getCheckedNum("pointIds") != 1) {
		alert("必须且只能选择一条编辑的功能点！");
		return;
	}
	window.location.href = "pointEdit.seam?pointId=" + getCheckboxValue("pointIds");
}

// 修改功能点
function modifyPoint() {
	if(checkPointForm()) {
		var pointForm = document.forms[0];
		var vo = Lseam.getType("cn.line5.module.ModuleFunctionPointVo");
		vo.setPointId(pointForm.pointId.value);
		vo.setFunctionId(pointForm.functionId.value);
		vo.setPointName(pointForm.pointName.value);
		vo.setComponentName(pointForm.componentName.value);
		vo.setMethodName(pointForm.methodName.value);
		Lseam.getComponent("moduleRemote").modifyPoint(vo, function(result) {
    		if(result) {
    			alert("修改成功！");
   				window.location.href = "pointList.seam?functionId=" + pointForm.functionId.value;
    		} else
    			alert("修改失败，请稍候重试！");
    	});
	}
}

// 删除功能点
function deletePoint() {
	if(getCheckedNum("pointIds") <= 0){
		alert("请选择要删除的功能点！");
		return;
	}
	if(confirm("该操作将删除选择的功能点，确定继续吗？")) {
		var pointForm = document.forms[0];
		pointForm.method = "post";
		pointForm.action = "pointDelete.seam";
		pointForm.submit();
	}
}

// 功能点向上排序
function upPoint(functionId, pointId) {
	Lseam.getComponent("moduleRemote").upPoint(functionId, pointId, function(result) {
		if(result)
			window.location.reload();
		else
			alert("排序操作失败，请稍候重试！");
	});
}

// 功能点向下排序
function downPoint(functionId, pointId) {
	Lseam.getComponent("moduleRemote").downPoint(functionId, pointId, function(result) {
		if(result)
			window.location.reload();
		else
			alert("排序操作失败，请稍候重试！");
	});
}